



let vm = new Vue({
    el:"#app",
    data:{
        name1:false,
        name2:false,
        name3:false,
        name4:false,
        name5:false,

        username:'',
        phone:'',
        email:'',
        password:'',
        confirm:'',

        username_err_msg:'',
        phone_err_msg:'',
        email_err_msg:'',
        password_err_msg:'',
        confirm_err_msg:'',

        username_hasError:false,
        phone_hasError:false,
        email_hasError:false,
        password_hasError:false,
        confirm_hasError:false,
    },
    methods:{
        register:function () {
            console.log("Submit")
            let form = new FormData()
            form.append("username",this.username)
            form.append("phone",this.phone)
            form.append("email",this.email)
            form.append("password",this.password)
            form.append("confirm",this.confirm)
            console.log(form)
            if(this.password!=this.confirm){
                this.confirm_err_msg="两次密码不一致！"
                this.confirm_hasError=true
            }
            axios({
                method:"post",
                url:"/register",
                data:form
            })
                .then(function (r){
                        console.log("|"+r.status+"|"+OK+"|")

                        if(r.data=="OK"){
                            console.log("注册成功！")
                            console.log(r.data)
                            location.href="/index.html"
                        }else{
                            console.log(r.data)
                            let message = r.data
                            if(message=="用户名已经存在！"){
                                vm.username_err_msg=message
                                vm.username_hasError=true
                            }else if(message=="手机号已经被注册！" || message=="手机号不正确！"){
                                vm.phone_err_msg=message
                                vm.phone_hasError=true
                            }else if(message=="邮箱已经被注册！"||message=="邮箱格式错误！"){
                                vm.email_err_msg=message
                                vm.email_hasError=true
                            }else{
                                vm.password_err_msg=message
                                vm.password_hasError=true
                            }

                        }
                    }
                )
        }
    },
    updated:function (){
        if(vm.phone!=""){
            vm.name1=true
        }else{
            vm.name1=false
        }

        if(vm.email!=""){
            vm.name2=true
        }else{
            vm.name2=false
        }

        if(vm.password!=""){
            vm.name3=true
        }else{
            vm.name3=false
        }

        if(vm.confirm!=""){
            vm.name4=true
        }else{
            vm.name4=false
        }
        if(vm.username!=""){
            vm.name5=true
        }else{
            vm.name5=false
        }
    }
})

let id=0;
$(".m-input:eq(0)").focus();
$(".m-input-icon").click(function (){
    id = $(this).parents(".my_form_group").index()
    if(id==0){
        vm.username=""
        $(".m-input:eq(0)").focus();
    }else if(id==1){
        vm.phone=""
        $(".m-input:eq(1)").focus();
    }else if(id==2){
        vm.email=""
        $(".m-input:eq(2)").focus();
    }else if(id==3){
        vm.password=""
        $(".m-input:eq(3)").focus();
    }
    else if(id==4){
        vm.confirm=""
        $(".m-input:eq(4)").focus();
    }
})
$(".m-input").click(function (){
    vm.username_hasError=false
    vm.phone_hasError=false
    vm.email_hasError=false
    vm.password_hasError=false
    vm.confirm_hasError=false

})
